//Copyright (c) 2012 Oskar Emil Skeide
//
//Permission is hereby granted, free of charge, to any person obtaining a copy of
//this software and associated documentation files (the "Software"), to deal in
//the Software without restriction, including without limitation the rights to
//use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
//of the Software, and to permit persons to whom the Software is furnished to do
//so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
var appData = Object.create(null);
var db;
var roConfig = {
		writable: false,
		enumerable: true,
		configurable: false
};

var defineROprop = function(obj, name, value){
	roConfig.value = value;
	Object.defineProperty(obj, name, roConfig);
}

defineROprop(appData, "vMajor", 0);		//Major version number
defineROprop(appData, "vMinor", 1);		//Minor version number
defineROprop(appData, "vRevision", 1);	//Build / Revision number.

function dbUpgrade(oldVersion, newVersion){
	if(oldVersion == ""){
		db.transaction(function(tx){
				//tx.executeSql("DROP TABLE IF EXISTS ServiceItem");
				tx.executeSql("CREATE TABLE IF NOT EXISTS ServiceItem(Id TEXT PRIMARY KEY, ParentId TEXT, Description TEXT, Icon TEXT, SortOrder INTEGER, FOREIGN KEY (ParentId) REFERENCES ServiceItem(Id))");
			},
			errorHandler,
			nullDataHandler);
	}	
}

function errorHandler(err){
	window.alert(
		"There was an error processing your request:\n" + 
		err + 
		"\n---\n" +
		err.name +
		"\n---\n" +
		err.message);
}

function nullDataHandler(){}

function longVersion(){
	 return shortVersion() + "." + formatNumber(appData.vRevision, 3);
}

function shortVersion(){
	return appData.vMajor + "." + formatNumber(appData.vMinor, 2);
}






